<template>
  <div class="header">
    <div class="item">
      <span class="icon icon-dingwei1"></span>
      <span>{{ address }}</span>
      <div class="arrow">
        <i class="el-icon-caret-top"></i>
        <i class="el-icon-caret-bottom"></i>
      </div>
    </div>
    <!-- <div class="item" @click="clickCard">
      <span class="icon redIcon icon-wupin"></span>
      <span>领取</span>
      <div class="arrow">
        <i class="el-icon-caret-top"></i>
        <i class="el-icon-caret-bottom"></i>
      </div>
    </div> -->
    <!-- <div class="item">
      <span class="icon yellowIcon icon-youhuiquan"></span>
      <span>优惠</span>
      <div class="arrow">
        <i class="el-icon-caret-top"></i>
        <i class="el-icon-caret-bottom"></i>
      </div>
    </div> -->
    <div class="item search-container">
      <el-input
        placeholder="请输入内容"
        v-model="myKeyword"
        class="search"
        clearable
        :readonly="isReadonly"
        @focus="focus"
      >
        <el-button
          slot="prepend"
          icon="el-icon-search"
          @click="clickSearch"
          @keydown.enter="clickSearch"
        ></el-button>
      </el-input>
    </div>
  </div>
</template>

<script>
export default {
  name: "headerItem",
  props: {
    address: {
      type: String,
      default() {
        return "这是一个默认地址";
      },
    },
    focus: {
      type: Function,
      default() {
        return () => {};
      },
    },
  },
  data() {
    return {
      drawer: false,
      isReadonly: true,
      myKeyword: "",
    };
  },
  created() {
    this.$bus.$on("historyKeyword", this.historyKeyword);
    this.$bus.$on("changeReadonly", this.changeReadonly);
  },
  beforeDestroy() {
    this.$bus.$off("historyKeyword", this.historyKeyword);
    this.$bus.$off("changeReadonly", this.changeReadonly);
  },
  methods: {
    clickSearch() {
      this.$bus.$emit("searchKeyword", this.myKeyword.trim());
    },
    historyKeyword(e) {
      this.myKeyword = e;
    },
    changeReadonly(e) {
      this.isReadonly = e;
    },
  },
};
</script>
<style scoped lang="less">
@num-14: 0.8rem;
@num-10: 0.5rem;
@num-36: 2rem;
@num-24: 1.2rem;
@num-8: 0.5rem;

/deep/.el-input__inner {
  height: @num-36 !important;
}

.header {
  width: 100%;
  height: 100%;
  align-items: center;
  display: flex;
  justify-content: space-between;

  .icon {
    font-size: 1.6rem;
  }

  .item {
    height: 100%;
    font-size: 1rem;
    font-weight: 700;
    color: #6a6868;
    display: flex;
    align-items: center;
    margin-right: 2.2rem;
    cursor: pointer;

    .arrow {
      width: @num-14;
      font-size: @num-14;
      margin-left: @num-10;
      display: flex;
      flex-direction: column;
      justify-content: space-around;

      i {
        width: @num-14;
        height: @num-14;
        color: rgb(156, 156, 169);
        line-height: @num-14;
        font-weight: 700;
      }

      i:hover {
        color: rgb(0, 0, 255);
        font-weight: 700;
      }
    }

    .icon {
      margin-right: @num-10;
      font-weight: 400;
    }

    .redIcon {
      color: #fb6d3a;
    }

    .yellowIcon {
      color: #facd5d;
    }
  }

  .search-container {
    flex: 1;
    margin: 0 3rem;
  }

  .search {
    width: 100%;
  }

  .right-float {
    margin-left: auto;
    display: flex;
    justify-content: space-around;
    width: 6%;

    .icon-dianpu1 {
      width: @num-36;
      height: @num-36;
      font-size: @num-24;
      line-height: @num-36;
      color: white;
      border-radius: @num-8;
      text-align: center;
      background-color: #503e9d;
    }

    .icon-wupingoumai {
      width: @num-36;
      height: @num-36;
      font-size: @num-24;
      line-height: @num-36;
      color: white;
      border-radius: @num-8;
      text-align: center;
      background-color: #fb6d3a;
    }
  }
}
</style>
